<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
</head>
<body>
<div id="main">
</div>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.min.js"></script>
<script type="text/javascript" src="../script/layer_mobile/layer.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script>
    new Vue({
        el: '#main',
        data: {
            code: '',
            userInfo: {}
        },
        mounted: function () {
            var $this = this;
            var code = this.getQueryVariable('code');
            $this.code = code;

            if (code) {
                $api.setStorage('CODE', code);
                top.location.replace(wxAppIndexPage);
            } else {
                var redirectUrl = encodeURI(wxLoginRedirectUrl);

                top.location = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + wxAppId + '&redirect_uri=' + redirectUrl + '&response_type=code&scope=SCOPE&agentid=' + wxAgentId + '&state=STATE#wechat_redirect';
                // top.location = wxLoginRedirectUrl + '?code=ZwWv-05BYsFkKI55Duvi0IiOBmkhIdUqYCBjNaVJHKU'
            }
        },
        methods: {
            getQueryVariable: function (variable) {
                var query = window.location.search.substring(1);
                var vars = query.split("&");
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == variable) {
                        return pair[1];
                    }
                }
                return false;
            }
        }
    });

</script>
</body>
</html>
